package com.lzy.product.apis.impl;

import com.github.pagehelper.PageInfo;
import com.lzy.framework.core.orm.db.Pager;
import com.lzy.product.apis.AgentProductServiceApi;
import com.lzy.product.apis.ProductUserServiceApi;
import com.lzy.product.dtos.ProductUserDto;
import com.lzy.product.dtos.agent.AgentProductDto;
import com.lzy.product.dtos.agent.AgentProductImageTextDto;
import com.lzy.product.dtos.agent.AgentProductProjectDto;
import com.lzy.product.dtos.agent.AgentProtocolProductDto;
import com.lzy.product.entity.AgentProductImageText;
import com.lzy.product.entity.AgentProductProject;
import com.lzy.product.entity.AgentProtocolProduct;
import com.lzy.product.service.AgentProductImageTextService;
import com.lzy.product.service.AgentProductProjectService;
import com.lzy.product.service.AgentProductService;
import com.lzy.product.service.AgentProtocolProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 代理商产品详情
 * Created by WIN7 on 2018/1/2.
 */
@Service
public class AgentProductServiceApiImpl implements AgentProductServiceApi {

    @Autowired
    private AgentProductService agentProductService;

    @Autowired
    private AgentProductProjectService agentProductProjectService;

    @Autowired
    private AgentProductImageTextService agentProductImageTextService;

    @Autowired
    private ProductUserServiceApi productUserServiceApi;

    @Override
    public Long insert(AgentProductDto dto) {
        return null;
    }

    @Override
    public Boolean update(AgentProductDto dto) {
        return agentProductService.update(dto);
    }

    @Override
    public Boolean delete(Long id) {
        return agentProductService.delete(id);
    }

    @Override
    public Boolean remove(Long id) {
        return agentProductService.remove(id);
    }

    @Override
    public AgentProductDto findById(Long id) {
        return null;
    }

    @Override
    public List<AgentProductDto> query(AgentProductDto dto) {
        return null;
    }

    @Override
    public PageInfo<AgentProductDto> queryAgentProductList(Pager pager, AgentProductDto paramDto) {
        PageInfo<AgentProductDto>  pageInfo =  agentProductService.queryAgentProductList(pager, paramDto);
        for (AgentProductDto agentProductDto: pageInfo.getList()) {
            if(agentProductDto!=null) {
                ProductUserDto productUserDto = productUserServiceApi.findById(agentProductDto.getCreateUser());
                if(productUserDto!=null) {
                    agentProductDto.setCreateUserName(productUserDto.getRealName());
                }
            }
        }
        return pageInfo ;
    }

    @Override
    public Boolean deleteAagntProductList(String ids) {
        return agentProductService.deleteAagntProductList(ids);
    }

    @Override
    public AgentProductDto queryAgentProductById(Long id) {
        List<AgentProductProjectDto> agentProtocolProductList = agentProductProjectService.queryAgentProductProject(id,1);
        List<AgentProductImageTextDto> agentProductImageTextList = agentProductImageTextService.queryAgentProductImageText(id);
        AgentProductDto agentProductDto = agentProductService.queryAgentProductById(id);
        if (agentProtocolProductList != null && agentProtocolProductList.size() > 0) {
            agentProductDto.setProductProjectDtos(agentProtocolProductList);
        }
        if (agentProductImageTextList != null && agentProductImageTextList.size() > 0) {
            agentProductDto.setProductImageTextDtos(agentProductImageTextList);
        }

        return agentProductDto;
    }

    @Override
    public Long createAagntProduct(AgentProductDto agentProductDto) {
        return agentProductService.createAagntProduct(agentProductDto);
    }

    @Override
    public PageInfo<AgentProductDto> queryAgentProductListByMobile(Pager pager, AgentProductDto paramDto) {
        return agentProductService.queryAgentProductList(pager, paramDto);
    }

}
